from selenium.webdriver.common.by import By
from base.page_base import BasePage


class LimitApplicationPage(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        # 切换身份
        self.change_id = (By.XPATH, '//*[@id="mlayout"]/div[2]/div[2]/div[1]/a/em')
        # 额度申请
        self.limit_app = (By.XPATH, '//*[@id="mlayout"]/div[2]/div[2]/div[3]/div[2]/dl/dd[4]/a')
        # 额度申请金额
        self.account = (By.ID, 'amount_account')
        # 详细信息
        self.detail = (By.NAME, 'remark')
        # 验证码
        self.code = (By.ID, 'verifycode')
        # 确认提交
        self.submit = (By.CSS_SELECTOR, '.btn-submit.btn-md')
        # 获取申请记录的金额
        self.res = (By.XPATH, '//*[@id="amount_list"]/tr[1]/td[3]')

    def limit_application(self, amount, detail, code):
        """
        额度申请提交
        :param amount: 额度金额
        :param detail: 详细信息
        :param code: 验证码
        :return: 无
        """
        self.base_click(self.change_id)
        self.base_click(self.limit_app)
        self.base_input(self.account, amount)
        self.base_input(self.detail, detail)
        self.base_input(self.code, code)
        self.base_click(self.submit)

    def get_success_result(self):
        """
        获取额度申请成功后的金额
        :return:
        """
        result = self.fd_element(self.res).text
        return result


